package com.zw.yzk.kabu.mapper;

import com.zw.yzk.kabu.data.network.entity.MessageListEntity;
import com.zw.yzk.kabu.model.MessageModel;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by zhanwei on 2017/3/4.
 */

public class MessageMapper {

    @Inject
    public MessageMapper() {

    }

    public MessageModel transfer(MessageListEntity.Message message) {
        MessageModel model = new MessageModel();
        model.setHead(message.head);
        model.setName(message.nickName);
        model.setTime(message.time);
        model.setAction(message.action + message.what);
        model.setId(message.actorId);
        model.setCosId(message.cosplyaId);
        model.setMessageId(message.messageId);
        model.setCosplayExist(message.cosplayExist == 1);

        return model;
    }

    public List<MessageModel> transfer(MessageListEntity entity) {
        List<MessageModel> models = new ArrayList<>();
        if(entity.result.messageList == null || entity.result.messageList.isEmpty()) {
            return models;
        }
        for(MessageListEntity.Message message : entity.result.messageList) {
            models.add(transfer(message));
        }
        return models;
    }
}
